package game.objects 
{
	import game.core.CollisionTypes;
	import game.core.GameManager;
	import game.core.Player;
	import game.objects.actions.Action;
	import net.flashpunk.Entity;
	/**
	 * ...
	 * @author Sulus Ltd.
	 */
	public class Building extends Entity
	{
		public var gameManager:GameManager;
		public var player:Player;
		public var controllable:Boolean = false;
		protected var controlled:Boolean = false;
		public var autoActions:Array = [];
		
		
		public function Building() 
		{
			type = CollisionTypes.building;
		}
		
		public function AddAction(action:Action):void
		{
			currentAction = 0;
			action.building = this;
			autoActions.push(action);
		}
		
		public function RemoveAction(action:Action):void
		{
			currentAction = 0;
			var idx:int = autoActions.indexOf(action);
			autoActions.splice(idx, 1);
		}
		public function DoActions():void
		{
			currentAction = 0;
			for each (var action:Action in autoActions) 
			{
				action.Execute();
			}
			
		}
		private var currentAction:int = 0;
		public function DoAction():Boolean
		{
			if (currentAction<autoActions.length)
			{
				var action:Action = autoActions[currentAction++];
				action.Execute();
				if (currentAction >= autoActions.length)
				{
					currentAction = 0;
					return true;
				} else
				return false;
			}
			
			return true;
			
		}
		
		public function SetControlled(orly:Boolean):void
		{
			controlled = orly;
		}
		
		public function IsControlled():Boolean
		{
			return controlled;
		}
		
		override public function update():void 
		{
			
		}
		
		protected function FinishTurn():void
		{
			gameManager.NextPhase();
		}
	}

}